﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ScoreDisplay : MonoBehaviour
{
    public ScoreManager scoreManager; // 引用 ScoreManager
    public Text scoreText;             // 引用 UI Text 组件
    // Start is called before the first frame update
    void Start()
    {
        scoreManager.OnScoreChanged += UpdateScoreDisplay;
    }
    // 响应得分变化事件
    private void UpdateScoreDisplay(int newScore)
    {
        scoreText.text = "得分: " + newScore;
    }
    private void OnDestroy()
    {
        // 取消订阅事件
        scoreManager.OnScoreChanged -= UpdateScoreDisplay;
    }
}
